package study.datastructure.array.leetcode;/**
 * @program: datastructure
 * @author: lcy
 * @create: 2024-12-07 16:59
 */

/**
 2024/12/7,
 */

import java.util.HashMap;
import java.util.Map;

/**
 * 两数之和
 */
public class Solution1 {


        public int[] twoSum(int[] nums, int target) {
            Map<Integer,Integer> hashTable = new HashMap<Integer, Integer>();
            for (int i=0; i<nums.length;i++) {
                if (hashTable.containsKey(target - nums[i])) {
                    return new int[]{hashTable.get(target-nums[i]),i};
                }
                hashTable.put(nums[i],i);
            }
            return new int[0];
        }

}
